﻿// ===============================================================================
// XCI.NET 西安交通信息WinForm开发框架 2018 版权所有
// ===============================================================================
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using DevExpress.Utils.Drawing;
using DevExpress.XtraBars.Ribbon;
using DevExpress.XtraBars.Ribbon.Gallery;
using DevExpress.XtraBars.Ribbon.ViewInfo;

namespace XCI.Helper
{
    /// <summary>
    /// Gallery控件辅助操作
    /// </summary>
    public class GalleryHelper
    {
        private void DrawMarkedIcon(GraphicsCache cache, Rectangle bounds)
        {
            RectangleF clipBounds = cache.Graphics.ClipBounds;
            RectangleF rect = cache.Graphics.ClipBounds;
            rect.Inflate(50, 50);
            cache.Graphics.SetClip(rect);
            var img = DevExpress.Images.ImageResourceCache.Default.GetImage("office2013/actions/apply_32x32.png");
            cache.Graphics.DrawImage(img, new Rectangle(bounds.Right - 26, bounds.Bottom - 26, 32, 32));
            cache.Graphics.SetClip(clipBounds);
        }

        private void Gallery_ItemCheckedChanged(object sender, GalleryItemEventArgs e)
        {
            GalleryControl gallery = ((GalleryControlGallery)sender).GalleryControl;
            List<GalleryItem> items = gallery.Gallery.GetCheckedItems();
            gallery.Refresh();
        }

        private void Gallery_CustomDrawItemImage(object sender, GalleryItemCustomDrawEventArgs e)
        {
            //if (!MarkedItems.Contains(e.Item)) return;
            e.Cache.Graphics.DrawImage(e.Item.Image, ((GalleryItemViewInfo)e.ItemInfo).ImageContentBounds);
            DrawMarkedIcon(e.Cache, ((GalleryItemViewInfo)e.ItemInfo).ImageContentBounds);
            e.Handled = true;
        }
    }
}
